pattern = "abba", s = "dog cat cat dog"
var wordPattern = function (pattern, s) {
    const arr = s.split(' ')
    if (pattern.length !== arr.length) {
        return false
    }
    for (let i = 0; i < arr.length; i++) {
        if (pattern.indexOf(pattern[i]) !== arr.indexOf(arr[i]))
            return false
    }
    return true
};
console.log(wordPattern(pattern, s));
